﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace DriveBeamEditor.Controls.General
{
    public partial class CollapsibleGroupBox : GroupBox
    {
        #region Fields

        private bool _isCollapsed = false;

        #endregion

        #region Properties

        public bool IsCollapsed
        {
            get { return _isCollapsed; }
            set
            {
                if (value) Collapse();
                else Expand();
            }
        }

        #endregion

        #region CTORs

        public CollapsibleGroupBox()
        {
            InitializeComponent();
            InitializeCollapseButton();
            Collapse();
        }

        #endregion

        #region Events

        private void xbCollapse_Click(object sender, EventArgs e)
        {
            if (_isCollapsed) Expand();
            else Collapse();
        }

        #endregion

        #region Methods

        private void InitializeCollapseButton()
        {
            xbCollapse.Size = new Size(20, 20);
            xbCollapse.Location = new Point(Width - 22, 2);
            xbCollapse.BringToFront();
        }

        public void Collapse()
        {
            if (_isCollapsed) return;

            _isCollapsed = true;
            xbCollapse.Text = @"+";
            Size = MinimumSize;
        }

        public void Expand()
        {
            if (!_isCollapsed) return;

            _isCollapsed = false;
            xbCollapse.Text = @"-";
            Size = MaximumSize;
        }

        #endregion
    }
}
